﻿using Microsoft.VisualBasic;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;

namespace reminder_to_stand_up_and_take_a_break_from_sitting_for_a_long_time
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class ellipse : Window
    {
        public main main2;
        public ellipse( main main2)
        {
            InitializeComponent();
            this.main2 = main2;
        }

        private void Ellipse_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {

            Debug.WriteLine(main2.Title);
            Debug.WriteLine(main2.restTime.Text);
            this.DragMove();
           
        }

        private void Ellipse_PreviewMouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {
            Debug.WriteLine("右击了按钮");

            //if (window2==null)
            //{
            //    window2 = new Window1();
            //}


            
            main2.Show();
            if (screentemp!=null)
            {
                screentemp.Hide();
            }
  
           
        }
        public DispatcherTimer timing;
       
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("第一次显示界面");
            timing = new DispatcherTimer();
            timing.Interval = new TimeSpan(0, 0, 1);
            timing.Tick += new EventHandler(time_Tick);
            timing.Start();            
        }



        public screen screentemp;
        void time_Tick(object sender,EventArgs e)
        {

            Timer.workTime = Timer.workTime.Subtract(TimeSpan.FromSeconds(1));   
            labelTime.Content = Timer.workTime.ToString(@"mm\:ss");
            if (Timer.workTime==Timer.rest)
            {
                Debug.Write("倒时计时10分钟已到");
                if (screentemp==null)
                {
                    screentemp = new screen();
                }
                screentemp.Show();
                screentemp.Activate();
                labelTime.Foreground = Brushes.Red;
            }
            if (Timer.workTime==TimeSpan.FromMinutes(0))
            {
                screentemp.Hide();
                labelTime.Foreground = Brushes.AliceBlue;
                Timer.workTime = TimeSpan.FromMinutes(int.Parse(main2.workTime.Text));
                Timer.rest = TimeSpan.FromMinutes(int.Parse(main2.restTime.Text));
            }
           
        }

        private void Window_Initialized(object sender, EventArgs e)
        {
            this.Top = SystemParameters.WorkArea.Height - this.Height;
            this.Left = SystemParameters.WorkArea.Width - this.Width;
        }
    }
}
